package com.example.imtoken.modules.main.wallet.collection

import androidx.recyclerview.widget.LinearLayoutManager
import com.example.imtoken.R
import com.example.imtoken.core.base.BaseFragment
import com.example.imtoken.databinding.CollectionFragmentBinding
import kotlinx.android.synthetic.main.collection_fragment.*

/**
 * 收藏
 * @property adapter CollectionAdapter
 */
class CollectionFragment :
    BaseFragment<CollectionViewModel, CollectionFragmentBinding>(CollectionViewModel::class.java) {

    private lateinit var adapter: CollectionAdapter

    override fun initLayoutId(): Int {
        return R.layout.collection_fragment
    }

    override fun init() {
        initAdapter()
        initObServe()
        initListener()
        viewModel.getData()
    }

    private fun initListener() {
        srlCollection.setOnRefreshListener {
            viewModel.getPageData()
            srlCollection.isRefreshing = false
        }
    }

    private fun initObServe() {
        viewModel.getCollectionLiveData().observe(this) {
            adapter.setList(it)
        }
    }

    private fun initAdapter() {
        adapter = CollectionAdapter(R.layout.item_collection_view)
        val layoutManager = LinearLayoutManager(context)
        rvCollection.layoutManager = layoutManager
        rvCollection.adapter = adapter
    }

}